import { http } from "@/utils/http";
import { baseUrlApi, filerEmptyVal } from "../utils";

/** 货主备货-列表 */
export const getPurchasePage = (params?: object) => {
  return http.request<any>("get", baseUrlApi("/purchase/order/page"), {
    params: filerEmptyVal(params)
  });
};

/** 添加货主备货 */
export const purchaseAdd = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/add"), { data });
};

/** 删除货主备货 */
export const purchaseDelete = (id?: object) => {
  return http.request<any>(
    "post",
    baseUrlApi(`/purchase/order/delete?id=${id}`)
  );
};

/** 货主备货详情[编辑用] */
export const purchaseDetail = id => {
  return http.request<any>(
    "get",
    baseUrlApi("/purchase/order/simple/detail?id=" + id)
  );
};

/** 编辑货主备货 */
export const purchaseUpdate = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/update"), {
    data
  });
};

/** 关闭货主备货 */
export const purchaseClose = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/order/close"), {
    data
  });
};

/** 运费到付 */
export const purchaseFareAdd = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/fare/add"), {
    data
  });
};

/** 新增运单号 */
export const purchaseAddBillNo = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/add/billNo"), {
    data
  });
};

/** 货主备货详情 */
export const purchaseOrderDetail = id => {
  return http.request<any>(
    "get",
    baseUrlApi("/purchase/order/detail?id=" + id)
  );
};

/** 删除运单号 */
export const delOrderBillNo = (data?: object) => {
  return http.request<any>(
    "post",
    baseUrlApi("/purchase/order/delete/billNo"),
    { data }
  );
};

/** 货主备货价格计算 */
export const purchaseOrderCalc = (data?: object) => {
  return http.request<any>("post", baseUrlApi("/purchase/order/calc"), {
    data
  });
};
